/*
 Copyright (C) 2010 QDSS.org
 
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.qdss.persist.engine;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;

/**
 * 弱ID生成器，只有20位长度
 * 
 * @author <a href="mailto:zhaofang123@gmail.com">Zhao Fangfang</a>
 * @since 0.2, 2010-8-11
 * @version $Id: WeakIDGenerator.java 144 2012-08-30 15:28:06Z zhaofang123@gmail.com $
 */
public class WeakIDGenerator extends IDGenerator {

	/**
	 * ENTITY_CODE - MO_TIME LO_TIME COUNT
	 */
	@Override
	public Serializable generate(Integer entityCode) {
		return new StringBuilder(getLength()).append(
				StringUtils.leftPad(entityCode + StringUtils.EMPTY, 3, '0')).append(SEP).append(
				format(getMoTime())).append(format(getLoTime())).append(format(getCount()))
				.toString();
	}
	
	@Override
	public int getLength() {
		return 20;
	}
}
